import re
import sys
from string import Template

def interpolate(string):
    
    outer_locals = sys._getframe(1).f_locals
    outer_locals.update(sys._getframe(1).f_globals)
    
    if hasattr('', 'format'):
        return re.sub(r'\#([a-zA-Z_][a-zA-Z0-9_]*)', r'#{\g<1>}', string).format(**outer_locals)
    
    else:
        del outer_locals['self']
        return Template(re.sub(r'\#([a-zA-Z_][a-zA-Z0-9_]*)', r'$\g<1>', string)).substitute(**outer_locals)
    

if __name__ == '__main__':
    name = "Jon Doe"
    #print interpolate('Hello i am #name')
